let messyArray: [string, number, boolean] = ['sdflh', 1231, true]

console.log("messyArray ==> ", messyArray);

enum types {
  coupon = 2,
  money = 3
}

console.log(types.coupon);


function sayName(name: string): string{
  console.log("my name is ", name);
  return name;
}

sayName("lucy")

// const error = (message: string): never => {
//   throw new Error(message)
// }

// error("absbcbj")

let someValue: any = "this is a string";

// let strLen = (<string>someValue).length
let strLen = (someValue as string).length

console.log(strLen);

// let strLength: number = (<string>someValue).length;
// let strLength: number = (someValue as string).length;

function getLength(something: string | number): number{
  // let len = something.length
  // console.log("len ==> ", len);
  if((<string>something).length){
    return (<string>something).length
  }else{
    return <number>something.toString().length
  }
}

console.log(getLength(123456), getLength("147"))


// function gen_func1<T>(arg: T): T {
//   return arg;
// }
// // 或者
// let gen_func2: <T>(arg: T) => T = function (arg) {
//   return arg;
// }
// gen_func1<string>('Hello world');
// gen_func2('Hello world'); 
// // 第二种调用方式可省略类型参数，因为编译器会根据传入参数来自动识别对应的类型。

function fun1<T>(arg: T){
  console.log("===> ", arg);
  
  return arg
}

fun1<string>("str")

const fun2: <T>(arg: T) => T = function(arg){
  console.log("arg ==> ", arg);
  return arg
}

fun2("fun2 arg")

// function any_func(value: any){
//   console.log("value.length ==> ", value.length);
// }
function any_func<T>(value: Array<T>){
  console.log("value.length ==> ", value.length);
}

// any_func("lfjdkf")
// any_func(undefined)
any_func([12, 56])

// 泛型接口 todo
interface Generics_interface<T> {
  (arg: T): T;
}

function func_demo<T>(arg: T): T {
  return arg;
}

let func1: Generics_interface<number> = func_demo;
func1(123);     // 正确类型的实际参数
// func1('123');   // 错误类型的实际参数

interface User{
  name: string,
  age: number
}

type User2 = {
  name: string,
  age: number
}

interface SetUser{
  User: void
}

// type SetUser2 = (name: string, age: number): void;

interface Name{
  name: string
}
interface User3 extends Name{
  age: number
}

type Name2 = {
  name: string
}

type User4 = Name2 & {age: number}

function wong(){
  console.log("wowoowo");
}

function miao(){
  console.log("miaomiao");
  
}

// // 基本类型别名
// type Name = string

// // 联合类型
// interface Dog {
//     wong();
// }
// interface Cat {
//     miao();
// }

// type Pet = Dog | Cat

// // 具体定义数组每个位置的类型
// type PetList = [Dog, Pet]


let div = 'string div';
type B = typeof div
  
let sss = 'strin'
// sss = 435
